package model.interactionhandler;

import java.util.List;

import model.Model;
import model.entity.Avatar;
import model.entity.BasicEntity;
import model.interactionHandlerInitializer.InteractionHandlerInitializer;

/**
 * The purpose of this class is to be something that the view can
 *  listen to in order to know what and when to populate the 
 *  interactions list. 
 * @author Vincent
 *
 */
public class InteractionContainer extends Model {
	
	static private InteractionContainer instance = null;
	
	private Avatar avatar;
	private BasicEntity target;
	private Boolean isInteracting;
	private List<InteractionHandlerInitializer> interactionHandlersInits;
	
	
	public static InteractionContainer getInstance() {
		if ( instance != null ) {
			return instance;
		}
		return instance = new InteractionContainer();
	}
	
	private InteractionContainer() {
		super("InteractionContainer");
		avatar = null;
		target = null;
		isInteracting = false;
		interactionHandlersInits = null;
	}
	
	public boolean isInteracting(){
		return isInteracting;
	}
	
	public void startInteraction(Avatar av, BasicEntity basicEnt) {
		this.clear();
		avatar = av;
		target = basicEnt;
		interactionHandlersInits = 
			BasicEntityHasInteractionInitializer.getInstance().getInteractions( basicEnt );
		isInteracting = true;
		super.updateSubscribers();
	}
	
	public void clear(){
		avatar = null;
		target = null;
		isInteracting = false;
		interactionHandlersInits = null;
		super.updateSubscribers();
	}
	
	public List<InteractionHandlerInitializer> getInteractions(){
		return interactionHandlersInits;
	}
	
	public Avatar getAvatar() {
		return this.avatar;
	}
	
	public BasicEntity getTarget() {
		return this.target;
	}
}
